package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.Activetyrecord;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.ActivetyrecordService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller //@Controller注解是用spring容器生成 对象 默认对象名 activetyrecordController
@RequestMapping("/activetyrecordController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /activetyrecordController
public class ActivetyrecordController {
	@Resource
    ActivetyrecordService activetyrecordService;
	@RequestMapping("/getAllActivetyrecord")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Activetyrecord> getAllActivetyrecord() throws Exception{
    	System.out.println("查询活动类型");
    	return activetyrecordService.getAllActivetyrecords();
    }
	@RequestMapping("/addActivetyrecord")
	@ResponseBody
	public DTO<Activetyrecord> addActivetyrecord(@RequestBody Activetyrecord activetyrecord) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加活动类型成功");
		return activetyrecordService.addActivetyrecord(activetyrecord);
	}

	@RequestMapping("/deleteActivetyrecordByAfno/{afno}")
	@ResponseBody
    public DTO<Activetyrecord> deleteActivetyrecordByAfno(@RequestBody @PathVariable("afno") String afno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(afno+"删除活动类型成功");
    	return activetyrecordService.deleteActivetyrecordByAfno(afno);
    }



	@RequestMapping("/getActivetyrecordByAfno/{afno}")
	@ResponseBody
	public DTO<Activetyrecord> getActivetyrecordByAfno(@PathVariable("afno") String afno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println(afno+"根据主键查询活动类型成功");
		return activetyrecordService.getActivetyrecordByAfno(afno);
	}

	@RequestMapping("/updateActivetyrecordByAfno")
	@ResponseBody
	public DTO<Activetyrecord> updateActivetyrecordByAfno(@RequestBody Activetyrecord activetyrecord) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改活动类型成功");
		System.out.println(activetyrecord);
		return activetyrecordService.updateActivetyrecordByAfno(activetyrecord);
	}

	@RequestMapping("/getActivetyrecordByPage")
	@ResponseBody
	public DTO<Activetyrecord> getActivetyrecordByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页查询活动类型成功");
		return activetyrecordService.getActivetyrecordByPage(pageInfo);
	}

}
